﻿@using com.hyrentals.webcommon.extensions
@using com.hyrentals.webportal.Config
@using com.hyrentals.data
@using com.hyrentals.common

@model com.hyrentals.data.RV
@{
    Html.AddStyle("css/calendar");
    Html.AddStyle("css/rv");
    Html.AddTailScript("js/rv-calendar");

    string calendarUrl = string.Format("/rv/{0}/edit/calendar", Model.Id);
    string pricingUrl = string.Format("/rv/{0}/edit/pricing", Model.Id);
    string overviewUrl = string.Format("/rv/{0}/edit/overview", Model.Id);
    string automotiveUrl = string.Format("/rv/{0}/edit/automotive", Model.Id);
    string interiorUrl = string.Format("/rv/{0}/edit/interior", Model.Id);
    string photosUrl = string.Format("/rv/{0}/edit/photos", Model.Id);
    string addressUrl = string.Format("/rv/{0}/edit/address", Model.Id);

    string availableAlwaysId = string.Format("availability_{0}", (byte)RVAvailabilityTypeEnum.Always);
    string availableSometimesId = string.Format("availability_{0}", (byte)RVAvailabilityTypeEnum.Sometimes);

    bool isAvailableAlwaysSelected = Model.AvailableType == RVAvailabilityTypeEnum.Always;
    bool isAvailableSometimesSelected = Model.AvailableType == RVAvailabilityTypeEnum.Sometimes;

    byte availableAlwaysValue = (byte)RVAvailabilityTypeEnum.Always;
    byte availableSometimesValue = (byte)RVAvailabilityTypeEnum.Sometimes;

    string availableAlwaysName = NameMapping.RVAvailabilityTypeEnumNameArray[availableAlwaysValue];
    string availableSometimesName = NameMapping.RVAvailabilityTypeEnumNameArray[availableSometimesValue];

    string hideStyle = null;
    if (isAvailableAlwaysSelected)
    {
        hideStyle = @"display: none;";
    }
}

<div class="layout-primary">
    <div class="layout-primary-left">
        <ul class="manage-rv-nav">
            <li><a class="active" href="@calendarUrl">Calendar</a></li>
            <li><a href="@pricingUrl">Pricing</a></li>
            <li><a href="@overviewUrl">Overview</a></li>
            <li><a href="@automotiveUrl">RV Details</a></li>
            <li><a href="@photosUrl">Photos</a></li>
            <li><a href="@addressUrl">Address</a></li>
        </ul>
    </div>
    <div class="layout-primary-middle">
        <form id="J_Calendar" class="form-s1 form-overview" action="" method="post">
            <div class="valid-simple">
            <input type="hidden" value="@Model.Id" name="id"/>

                <div class="row clearfix">
                        <label for="@availableAlwaysId">
                        @if (isAvailableAlwaysSelected)
                        {
                            <input class="type-radio" type="radio" value="@availableAlwaysValue" id="@availableAlwaysId" name="availability" checked="checked"/>
                        }
                        else
                        {
                            <input class="type-radio" type="radio" value="@availableAlwaysValue" id="@availableAlwaysId" name="availability"/>
                        }
                        <span>@availableAlwaysName</span>
                    </label>
                        <label for="@availableSometimesId">
                        @if (isAvailableSometimesSelected)
                        {
                            <input class="type-radio" type="radio" value="@availableSometimesValue" id="@availableSometimesId" name="availability" checked="checked"/>
                        }
                        else
                        {
                            <input class="type-radio" type="radio" value="@availableSometimesValue" id="@availableSometimesId" name="availability"/>
                        }
                            <span>@availableSometimesName</span>
                    </label>
                </div>

                <ul class="date-list" style="@hideStyle">
                @if (Model.AvailableDateIntervals != null)
                {
                    foreach (RVAvailableDateInterval dateInterval in Model.AvailableDateIntervals)
                    {
                        string index = GUIDHelper.Generate32GUID();
                        string startDateName = string.Format("dateIntervals[{0}].StartDate", index);
                        string endDateName = string.Format("dateIntervals[{0}].EndDate", index);
                        
                        string startDateStr = FormatHelper.FormatAsDate(dateInterval.StartDate);
                        string endDateStr = FormatHelper.FormatAsDate(dateInterval.EndDate);
                        string startEndDateStr = string.Format("{0} -> {1}", startDateStr, endDateStr);
                        <li class="date-item">
                        @if(dateInterval.StartDate == dateInterval.EndDate)
                        {
                            <input type="hidden" name="dateIntervals.Index" value="@index"/>
                            <a class="start btn btn1" href="javascript:;">@startDateStr</a>
                            <input class="start-storage" type="hidden" name="@startDateName" value="@startDateStr"/>
                            <input class="end-storage" type="hidden" name="@endDateName" value="@endDateStr"/>
                            <a class="delete" href="javascript:;" onclick="func.deleteDate(this); return false;">Delete</a>
                        }
                        else
                        {
                            <input type="hidden" name="dateIntervals.Index" value="@index"/>
                            <a class="start-end btn btn1" href="javascript:;" >@startEndDateStr</a>
                            <input class="start-storage" type="hidden" name="@startDateName" value="@startDateStr"/>
                            <input class="end-storage" type="hidden" name="@endDateName" value="@endDateStr"/>
                            <a class="delete" href="javascript:;" onclick="func.deleteDate(this); return false;">Delete</a>
                        }
                        </li>
                    }
                }
                </ul>
                <div class="row clearfix">
                    <a id="J_Sumbit" href="javascript:;" class="btn btn-large submit">Save</a>
                    <a id="J_AddADay" href="javascript:;" class="btn btn-large" style="@hideStyle">Add a Day</a>
                    <a id="J_AddDateInterval" href="javascript:;" class="btn btn-large" style="@hideStyle">Add Date Interval</a>
                </div>
            </div>
        </form>
    </div>
    <div class="layout-primary-right"></div>
</div>